package cn.signalpha.modules.shop.service;

import cn.signalpha.core.tool.utils.ObjectUtil;
import cn.signalpha.modules.shop.entity.Adorn;
import cn.signalpha.modules.shop.mapper.AdornMapper;
import cn.signalpha.modules.shop.vo.AdornVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 服务类
 *
 * @author signalpha
 */
@Service
public class AdornService extends ServiceImpl<AdornMapper, Adorn> {

	/**
	 * 自定义分页
	 */
    public IPage<AdornVO> selectAdornPage(IPage<AdornVO> page, Map<String, Object> params) {
        return page.setRecords(baseMapper.selectAdornPage(page, params));
    }

    /**
	 * 自定义Wrappers
	 */
    public QueryWrapper<Adorn> selectAdornWrapper(Map<String, Object> params) {
        QueryWrapper<Adorn> wrapper = Wrappers.query();
        wrapper.lambda().eq(ObjectUtil.isNotEmpty(params.get("id")), Adorn::getId, params.get("id"));
        wrapper.lambda().eq(ObjectUtil.isNotEmpty(params.get("name")), Adorn::getName, params.get("name"));
        wrapper.lambda().eq(ObjectUtil.isNotEmpty(params.get("isUse")), Adorn::getIsUse, params.get("isUse"));
        wrapper.lambda().eq(ObjectUtil.isNotEmpty(params.get("config")), Adorn::getConfig, params.get("config"));
        wrapper.lambda().eq(ObjectUtil.isNotEmpty(params.get("createTime")), Adorn::getCreateTime, params.get("createTime"));
        wrapper.lambda().eq(ObjectUtil.isNotEmpty(params.get("updateTime")), Adorn::getUpdateTime, params.get("updateTime"));
        wrapper.lambda().orderByDesc(Adorn::getId);
        return wrapper;
    }

	/**
	 * 获取使用中数据
	 */
	public Adorn getByUse() {
		return baseMapper.selectOne(Wrappers.<Adorn>lambdaQuery().eq(Adorn::getIsUse, 1).last("limit 1"));
	}

}

